package com.enums;

import org.springframework.util.StringUtils;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * @classDesc: 功能描述:
 * @author: 李明杰
 * @date: 2021/11/13 3:32
 * @copyright 众阳健康
 */

public class EnumUtils {
    public void getEnum() throws Exception {
        HashMap<String, String> map = new HashMap<>();
        Class aClass;

        StringBuffer buffer = new StringBuffer();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            if (!StringUtils.isEmpty(entry.getValue())) {
                try {
                    aClass = Class.forName("com.enums." + entry.getKey() + "Enum");
                } catch (ClassNotFoundException e) {
                    System.err.println("com.enums." + entry.getKey() + "Enum获取反射异常:" + e);
                    continue;
                }
                String[] split = entry.getValue().split(",");
                Method getMeaning = aClass.getDeclaredMethod("getMeaning", String.class);
                Object[] enumConstants = aClass.getEnumConstants();
                for (String str : split) {
                    buffer.append((String) getMeaning.invoke(enumConstants[0], str)).append(",");
                }
                // 此处的处理，为了在查询的时候可以直接使用in语法，而不用转为list使用in
                map.put(entry.getKey(), "(" + entry.getValue() + ")");
            }
        }
    }

}
